/*
 * ImageData.java
 * Created on August 12, 2008, 3:40 PM by Uru
 *
 * Description
 */

package ImageSystem;

import java.awt.image.*;
import java.awt.*;
import javax.swing.*;

public class ImageData {
    
    protected Image image;      //an actual instantiated image
    protected String filename;  //the filename of the image (if available)
    
    //Creates a new instance of ImageData
    public ImageData(Image i) {
        image = i;
        filename = null;
    }
    
    //Creates a new instance of ImageData
    public ImageData(Image i, String f) {
        image = i;
        filename = f;
    }
    
    //Creates a new instance of ImageData
    public ImageData(String f) {
        image = null;
        filename = f;
    }
    
    //returns the image, loading the image from file first if needed
    //it retains the loaded image to speed up future use
    public Image getImage(){
        if(image != null){
            return image;
        }
        Image i = new ImageIcon(filename).getImage();
        image = i;
        return i;
    }
    
    //draw the image at the given coordinates
    public void drawImage(int x, int y, Graphics2D g, JComponent io){
        if(image == null){
            image = new ImageIcon(filename).getImage();
        }
        if(image != null)g.drawImage(image,x,y,io);
    }
    
}
